package com.sh3h.generator.web.dtos;


import com.sh3h.generator.web.enums.AppExceptionCodeMsg;

public class Result<T> {

    //状态码
    private int code = 200;
    //状态码信息
    private String msg = "success";
    //返回的信息
    private T data;

    private Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> Result success(T data) {
        Result result = new Result(200, "success", data);
        return result;
    }

    public static <T> Result success(String msg, T data) {
        Result result = new Result(200, msg, data);
        return result;
    }

    public static <T> Result error(AppExceptionCodeMsg appExceptionCodeMsg) {
        Result result = new Result(appExceptionCodeMsg.getCode(), appExceptionCodeMsg.getMsg(), null);
        return result;
    }

    public static <T> Result error(int code, String msg) {
        Result result = new Result(code, msg, null);
        return result;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }

}

